home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / s1_hello.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  3KB  |  114 lines

  1. {$X+,B-,V-}
  2. program SendHello;
  3.  
  4. { Simple IPX demonstration program with 1 ESR.}
  5.  
  6. uses crt,nwMisc,nwIPX;
  7.  
  8. CONST IOSocket=$5678;
  9.  
  10. Var NewStack   :array[1..512] of word; { !! used by ESR }
  11.     StackBottom:word;                  { !! used by ESR }
  12.  
  13.     SendEcb    :Tecb;
  14.     IpxHdr     :TipxHeader;
  15.     socket     :word;
  16.     dest       :TinternetworkAddress;
  17.     buf        :array[1..546] of byte;
  18.     t          :byte;
  19.     w          :word;
  20.     s          :string;
  21.     PacketSent :boolean;
  22.  
  23. {$F+}
  24. Procedure SendESRhandler;
  25. begin
  26. PacketSent:=true;
  27. end;
  28. {$F-}
  29.  
  30. {$F+}
  31. Procedure SendESR; assembler;
  32. asm { ES:SI are the only valid registers when entering this procedure ! }
  33.     mov dx, seg stackbottom
  34.     mov ds, dx
  35.  
  36.     mov dx,ss  { setup of a new local stack }
  37.     mov bx,sp  { ss:sp copied to dx:bx}
  38.     mov ax,ds
  39.     mov ss,ax
  40.     mov sp,offset stackbottom
  41.     push bx
  42.     push dx
  43.  
  44.     CALL SendEsrHandler
  45.  
  46.     pop dx
  47.     pop bx
  48.     mov sp,bx { restore stack }
  49.     mov ss,dx
  50. end;
  51. {$F-}
  52.  
  53. begin
  54. IF NOT IpxInitialize
  55.  then begin
  56.       writeln('Ipx needs to be installed.');
  57.       halt(1);
  58.       end;
  59. socket:=IOSocket;
  60. IF NOT IPXopenSocket(Socket,SHORT_LIVED_SOCKET)
  61.  then begin
  62.       writeln('IPXopenSocket returned error# ',nwIPX.result);
  63.       halt(1);
  64.       end;
  65.  
  66. for t:=1 to 4 do dest.net[t]:=$00; { this net / segment }
  67. for t:=1 to 6 do dest.node[t]:=$FF; { all nodes }
  68. dest.socket:=IOsocket;
  69. w:=0;
  70.  
  71. Repeat
  72.   inc (w);
  73.  
  74.   { Fill buffer (ECB.fragment[2]^) }
  75.   str(w:4,s);
  76.   s:=s+' IPX: Hello World';
  77.   FillChar(buf,546,#0);
  78.   move(s[1],buf,ord(s[0]));
  79.  
  80.   { setup ECB and IPX header }
  81.   PacketSent:=False;
  82.   IPXsetupSendECB(Addr(SendESR),IOsocket,dest,@buf,ord(s[0]),
  83.                   IpxHdr,SendEcb);
  84.   IPXsendPacket(SendEcb);
  85.  
  86.   REPEAT
  87.  
  88.   IpxRelinquishControl;
  89.   delay(100);
  90.  
  91.   IF PacketSent
  92.    then begin
  93.         { ECB.InUseFlag was lowered, now determine if packet was sent: }
  94.         CASE SendEcb.CompletionCode OF
  95.          $00:writeln('IPX packet #',w:0,' was sent.');
  96.          $FC:writeln('The send of packet #',w:0,' was canceled.');
  97.              { impossible, as this cancelation to be done by THIS program, and it doesn't }
  98.          $FD:writeln('Packet# ',w:0,' is malformed and was not sent.');
  99.              { illegal param: packet length, number of fragments, fragment size. }
  100.          $FE:writeln('Packet# ',w:0,' was undelivered. No stations listening.');
  101.          $FF:writeln('Packet# ',w:0,' not sent due to a hardware error.');
  102.         end;
  103.         end;
  104.  
  105.   UNTIL PacketSent or Keypressed;
  106.  
  107.   delay(750); { delay 0.75 sec before sending another packet }
  108.  
  109. UNTIL keypressed;
  110.  
  111. IF NOT IPXcloseSocket(IOsocket)
  112. then writeln('IPXcloseSocket returned error# ',nwIPX.result);
  113.  
  114. end.